package algorithms.leecode;

import java.util.Arrays;

public class Au88 {
    public static void main(String[] args) {
        new Au88().merge(new int[]{2,0,0,0,0},1,new int[]{1,2,3,4,5},5);
    }
    public void merge(int[] nums1, int m, int[] nums2, int n) {


        int sum = nums1.length - 1;
        int r1 = m-1;
        int r2 = n-1;
        for (int i = sum; i >= 0; i--) {
            if (r2 >= 0 && r1 >= 0) {
                int num1 = nums1[r1];
                int num2 = nums2[r2];
                if (num1 > num2) {
                    nums1[i] = num1;
                    r1--;
                } else {
                    nums1[i] = num2;
                    r2--;
                }
            } else if (r1 < 0) {
                nums1[i] = nums2[r2];
                r2--;
            }
        }
        Arrays.stream(nums1).forEach(System.out::print);
    }
}
